Skip to content

Conversation

koxudaxi
Copy link
Contributor

@koxudaxi koxudaxi commented May 29, 2025

Adds parsing support for PEP 750 Template Strings, a new Python 3.14 feature that introduces t-strings for safer templating.

Overview

Template strings use the t prefix and create Template objects instead of regular strings, enabling secure HTML/SQL templating and DSL support:

# Basic template string
name = "world"
template = t"Hello, {name}!"

# Multi-line with format specifiers
html = t"""
<div class="user">
    <h1>{user.name}</h1>
    <p>Score: {score:04d}</p>
</div>
"""

Changes

  • Added Template flag to scanner for t-prefixed string literals
  • Extended scanner to recognize t/T prefixes (supports tr/rt combinations)
  • Template strings reuse existing f-string interpolation mechanism
  • Added comprehensive test coverage with 8 test cases

Related

Template strings will be available in Python 3.14.0b1+ and officially released in Python 3.14.

@wetneb
Copy link
Contributor

wetneb commented Sep 10, 2025

Hi @koxudaxi,

I'm not a maintainer here but want to thank you for your changes, which look great to me. I've integrated them in a fork of this repository since I have little hopes that this gets merged here soon.

The fork is published on crates.io - if you need to have it published elsewhere let me know.

@amaanq amaanq force-pushed the feature/pep-750-template-strings branch from 27ab141 to 6f562d4 Compare September 11, 2025 04:47
@amaanq amaanq force-pushed the feature/pep-750-template-strings branch from 6f562d4 to 8fecdc8 Compare September 11, 2025 04:48
@amaanq amaanq merged commit d8f9e69 into tree-sitter:master Sep 11, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants